#!/usr/bin/perl -w
use PDF::API2;
use strict;
use warnings;

sub makePdfFile
{
    my ($destination,$message) = @_;
    die "Missing destination" unless defined($destination);
    die "Missing message" unless defined($message);    

    # Create a blank PDF file
    my $pdf = PDF::API2->new();

    # Open an existing PDF file
    $pdf = PDF::API2->open('/usr/local/bin/modelloFax.pdf');

    # Retrieve an existing page
    my $page = $pdf->openpage(-1);

    # Set the page size
    $page->mediabox('A4');

    # Add a built-in font to the PDF
    my $font = $pdf->corefont('Georgia');

    # Add some text to the page
    my $altezza=650;

    my $text = $page->text();
    $text->font($font, 10);
    $text->translate(60, $altezza);
    $text->text("Destinazione: $destination");

    my @values = split(/\n/, $message);    
    $altezza=$altezza-30;
    foreach my $val (@values)
    {
        
        $text->translate(60, $altezza);
        $text->text($val);
        $altezza -=30;
    }
    # Save the PDF
    $pdf->saveas('test.pdf');
}

makePdfFile('test',"ci siamo\n provavfvf\n vfvf");